package com.epoint.mobileoa.personalized.epointcompany.ui.todolist;

import java.text.ChoiceFormat;
import java.util.HashMap;
import java.util.List;

import android.graphics.Color;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.epoint.mobileoa.R;
import com.epoint.mobileoa.bizlogic.SuperView;
import com.epoint.mobileoa.bizlogic.Task;
import com.epoint.mobileoa.datanalysis.XMLHelp;
import com.epoint.mobileoa.model.OperationBtn;
import com.epoint.mobileoa.model.WorkFlowProcessModel;
import com.epoint.mobileoa.service.MainService;
import com.epoint.mobileoa.tools.ControlsHelp;
import com.epoint.mobileoa.tools.StringHelp;
import com.epoint.mobileoa.tools.ToastHelp;

/**
 * @author liyc
 * @time 2012-5-10 下午2:37:23
 * @annotation 保证金申请
 */
public class BaozhengjinDetailView extends SuperView {

	private WebView wv;
	private TextView tvShjl,tvDqclbz,tvTjr;
	private LinearLayout llOperation,llShjl;
	private String messageitemguid,archiveguid,typecode,dqbuzhou,tjr;
	@Override
	public void initControls() {
		llShjl = (LinearLayout) findViewById(R.id.llShjl);
		wv = (WebView) findViewById(R.id.wvContent);
		tvShjl = (TextView) findViewById(R.id.tvShjl);
		setTextViewFontColor(tvShjl);
		tvDqclbz = (TextView) findViewById(R.id.tvDqclbz);
		tvTjr = (TextView) findViewById(R.id.tvTjr);
		llOperation = (LinearLayout)findViewById(R.id.llOperation);
		wv.setBackgroundColor(0);
		messageitemguid = getIntent().getStringExtra("messageitemguid");
		archiveguid = getIntent().getStringExtra("archiveguid");
		typecode = getIntent().getStringExtra("typecode");
		dqbuzhou = getIntent().getStringExtra("dqbuzhou");
		tjr = getIntent().getStringExtra("tjr");

		tvDqclbz.setText(Html.fromHtml("<font color=red>当前处理步骤:</font><font color=black>"+dqbuzhou+"</font>"));
		
		top_pb.setVisibility(View.VISIBLE);
		HashMap<String,Object> param=new HashMap<String,Object>();
		param.put("messageitemguid", messageitemguid);
		param.put("archiveguid", archiveguid);
		param.put("typecode", typecode);
		Task task = new GetBaozhengjinDetailTask(this, param);
		MainService.addTask(task);
	}

	@Override
	public void refresh(Object... param) {
		if(param[0].toString().equals(MainService.NORMAL)){
			String bs = param[1].toString();
			if(bs.contains("<result>none</result>")){
				ToastHelp.showToast(this, "记录不存在");
			}
			else{
				String ApplyUser = StringHelp.getXMLAtt(bs, "ApplyUser");
				String ApplyDate = StringHelp.getXMLAtt(bs, "ApplyDate");
				String ComfirmTypeName = StringHelp.getXMLAtt(bs, "ComfirmTypeName");
				String DeptBelongName = StringHelp.getXMLAtt(bs, "DeptBelongName");
				String ProjectMC = StringHelp.getXMLAtt(bs, "ProjectMC");
				String MYdept_bid = StringHelp.getXMLAtt(bs, "MYdept_bid");
				String ACdept_bid = StringHelp.getXMLAtt(bs, "ACdept_bid");
				String PayWayName = StringHelp.getXMLAtt(bs, "PayWayName");
				String ReceiveDept = StringHelp.getXMLAtt(bs, "ReceiveDept");
				String CustomerBank = StringHelp.getXMLAtt(bs, "CustomerBank");
				String Account = StringHelp.getXMLAtt(bs, "Account");
				String MoneyNum = StringHelp.getXMLAtt(bs, "MoneyNum");
				String ApplyReason = StringHelp.getXMLAtt(bs, "ApplyReason");

				StringBuilder sbhtml = new StringBuilder();
				sbhtml.append(StringHelp.getSingleFaWenData(this,"申请人：", ApplyUser));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"申请日期：", ApplyDate.substring(0,10)));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"保证金类型：", ComfirmTypeName));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"所属部门：", DeptBelongName));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"项目名称：", ProjectMC));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"名义投标单位：", MYdept_bid));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"实际投标单位：", ACdept_bid));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"付款方式：", PayWayName));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"收款单位：", ReceiveDept));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"开户行：", CustomerBank));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"账号：", Account));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"金额：", MoneyNum));
				sbhtml.append(StringHelp.getSingleFaWenData(this,"申请说明：", ApplyReason));

				wv.loadDataWithBaseURL(null, sbhtml.toString(),"text/html","utf-8",null);
				
				//审核记录
				String processliststr = StringHelp.getXMLAttOut(bs, "processlists");
				
				List<WorkFlowProcessModel> processlist = XMLHelp.WorkFlowProcessAnalysis(processliststr);
				
				
				int tvcolor = Color.argb(55, 0, 255, 0);
				
				for(int i=0;i<processlist.size();i++){
					WorkFlowProcessModel a = processlist.get(i);
					TextView tv = new TextView(this);
					StringBuilder sbpro = new StringBuilder();
					sbpro.append(StringHelp.getProcessHtml(this,"【步骤】", a.step));
					sbpro.append(StringHelp.getProcessHtml(this,"【办理人员】", a.dealer));
					sbpro.append(StringHelp.getProcessHtml(this,"【操作】", a.OperationName));
					sbpro.append(StringHelp.getProcessHtml(this,"【收到时间】", a.shoudaoTime));
					sbpro.append(StringHelp.getProcessHtml(this,"【处理时间】", a.dealDate));
					sbpro.append("<font size=2 color="+getYGColor()+">"+"【办理意见】"+"</font><font size=2 color="+getBlackOrWhiteColor()+">"+a.opinion+"</font>");
					
					tv.setBackgroundColor(tvcolor);
					
					tv.setText(Html.fromHtml(sbpro.toString()));
					
					llShjl.addView(tv);
					llShjl.addView(ControlsHelp.getLineTextView(this));
//					if(tvcolor==Color.argb(55, 0, 255, 0)){
//						tvcolor = Color.DKGRAY;
//					}
//					else{
//						tvcolor = Color.argb(55, 0, 255, 0);
//					}
				}
				
				String btnStr = StringHelp.getXMLAttOut(bs, "operationMessage");
				List<OperationBtn> btnlist = XMLHelp.OperationBtnAna(btnStr);
				for(int i=0;i<btnlist.size();i++){
					Button btOperation = new Button(this);
					final String btnName = btnlist.get(i).operationname;
					btOperation.setText(btnName);
					btOperation.setTag(i);
					btOperation.setBackgroundResource(R.drawable.bt_style1);
					btOperation.setTextColor(Color.WHITE);
					btOperation.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							if(btnName.equals("送下一步")||btnName.equals("退回")||btnName.equals("下一步审批")||btnName.equals("送下一步")||btnName.equals("提交财务")){
								ToastHelp.showToast(BaozhengjinDetailView.this, "暂时请在PC端处理该步骤");
							}
							else{
								ToastHelp.showToast(BaozhengjinDetailView.this, "请在PC端处理该步骤");
							}
						}
					});
					llOperation.addView(btOperation);
				}
			}
		}
		top_pb.setVisibility(View.GONE);
	}

	@Override
	public int getLayoutInt() {
		return R.layout.baozhengjindetailview;
	}

	@Override
	public String setTitle() {
		return "保证金申请";
	}

	@Override
	public void refreshForNewTask(int TaskId,Object... param){
	}

}
